* March 12, 2021
* national_terror, do-file

set matsize 500
set more off

use "C:\07102020\research, journal papers\nationalism and ethnic terror\do and log-files\replication materials\data\national_terror, data.dta", clear
	 

***** Table 1 *****
sum attack v2exl_legitideolcr_0_lagged xpolity2 status_autonomy status_powerless status_discrim status_separatist ///        
    Weighted_Conflict_Index_lag_log cw_binary ///                                                                   
	log_rgdppc_lag ///                                                                                                   
	muspct_lagged ///                                                                                                                         
	groupsize excl_groups_count ///                                                                                                           
	if isrelevant==1 


***** Table 2 *****
* Model 1
menbreg attack v2exl_legitideolcr_0_lagged xpolity2 status_autonomy status_powerless status_discrim status_separatist ///        
    Weighted_Conflict_Index_lag_log cw_binary ///                                                                   
	log_rgdppc_lag ///                                                                                                   
	muspct_lagged ///                                                                                                                         
	groupsize excl_groups_count ///                                                                                                           
	if isrelevant==1||cowcode: ||cowgroupid: ,cov(uns)
* Model 2
sort cowgroupid year 
xtabond2 attack v2exl_legitideolcr_0_lagged xpolity2 status_autonomy status_powerless status_discrim status_separatist ///       
    Weighted_Conflict_Index_lag_log cw_binary ///                                                                   
	log_rgdppc_lag ///                                                                                                   
	muspct_lagged ///                                                                                                                         
	groupsize excl_groups_count L.attack ///                                                                                                           
	if isrelevant==1, gmm (v2exl_legitideolcr_0_lagged, lag (1 5)) ///
	ivstyle(xpolity2   status_autonomy status_powerless status_discrim status_separatist ///       
    Weighted_Conflict_Index_lag_log cw_binary   ///                                                                   
	log_rgdppc_lag ///                                                                                                   
	muspct_lagged ///                                                                                                                         
	groupsize excl_groups_count L.attack)

	
***** Figure 1 *****
menbreg attack v2exl_legitideolcr_0_lagged xpolity2 status_autonomy status_powerless status_discrim status_separatist ///        
    Weighted_Conflict_Index_lag_log cw_binary ///                                                                   
	log_rgdppc_lag ///                                                                                                   
	muspct_lagged ///                                                                                                                         
	groupsize excl_groups_count ///                                                                                                           
	if isrelevant==1||cowcode: ||cowgroupid: ,cov(uns)
est store mod1	
coefplot (mod1, label(Model 1) pstyle(p5) msymbol(T)), drop(_cons) xline(0) xtitle(Average Marginal Effects) ///
         order(v2exl_legitideolcr_0_lagged xpolity2 status_autonomy status_powerless status_discrim status_separatist ///
               Weighted_Conflict_Index_lag_log cw_binary log_rgdppc_lag muspct_lagged groupsize excl_groups_count) ///
         coeflabel(v2exl_legitideolcr_0_lagged = "Leader Nationalism" xpolity2 = "Democracy" status_autonomy = "Regional Autonomy" status_powerless = "Powerless" status_discrim = "Discriminated" status_separatist = "Separatist" ///
		           Weighted_Conflict_Index_lag_log = "Political Instability" cw_binary = "Civil War" log_rgdppc_lag = "Econ Development" muspct_lagged = "Muslims" groupsize = "Group Size" ///
				   excl_groups_count = "Terrorist Outbidding") ///
         ciopts(recast(rcap))
estimates clear


***** Table 3 *****
* Model 1, no mixed effects
xtset cowgroupid year, yearly
nbreg attack v2exl_legitideolcr_0_lagged xpolity2 status_autonomy status_powerless status_discrim status_separatist ///        
    Weighted_Conflict_Index_lag_log cw_binary ///                                                                   
	log_rgdppc_lag ///                                                                                                   
	muspct_lagged ///                                                                                                                         
	groupsize excl_groups_count ///                                                                                                           
	if isrelevant==1 
* Model 2, lagged DV
menbreg attack v2exl_legitideolcr_0_lagged xpolity2 status_autonomy status_powerless status_discrim status_separatist ///        
    Weighted_Conflict_Index_lag_log cw_binary ///                                                                   
	log_rgdppc_lag ///                                                                                                   
	muspct_lagged ///                                                                                                                         
	groupsize excl_groups_count L.attack ///                                                                                                           
	if isrelevant==1||cowcode: ||cowgroupid: , cov(uns) 
* Model 3, alternative nationalism measure: nationalism_executive_1
menbreg attack nationalism_executive_1 xpolity2 status_autonomy status_powerless status_discrim status_separatist ///        
    Weighted_Conflict_Index_lag_log cw_binary ///                                                                   
	log_rgdppc_lag ///                                                                                                   
	muspct_lagged ///                                                                                                                         
	groupsize excl_groups_count ///                                                                                                           
	if isrelevant==1||cowcode: ||cowgroupid: ,cov(uns)
* Model 4, region
sort cowcode year
replace americas = americas[_n-1] if missing(americas) 
replace europe = europe[_n-1] if missing(europe) 
replace africa = africa[_n-1] if missing(africa) 
replace middleeast = middleeast[_n-1] if missing(middleeast) 
replace asia = asia[_n-1] if missing(asia) 
replace oceanania = oceanania[_n-1] if missing(oceanania) 
menbreg attack v2exl_legitideolcr_0_lagged xpolity2 status_autonomy status_powerless status_discrim status_separatist ///        
    Weighted_Conflict_Index_lag_log cw_binary ///                                                                   
	log_rgdppc_lag ///                                                                                                   
	muspct_lagged ///                                                                                                                         
	groupsize excl_groups_count americas europe africa middleeast asia ///                                                                                                           
	if isrelevant==1||cowcode: ||cowgroupid: ,cov(uns)
















